home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 5
/
BBS in a Box -Volume V (BBS in a Box) (April 1992).iso
/
Files
/
Word
/
O-P
/
Optical Lens
< prev
next >
Wrap
Text File
|
1987-11-22
|
4KB
|
119 lines
' ********************************************
' Lens Reduction by
' Elian George Marrash Spring 1986
' ********************************************
' This program is written in Microsoft Basic V2.0 For the
' Apple Macintosh Computer.
' ********************************************
' The purpose of this program is to preform geometrical
' optical analysis, by the use of matrix methods. It should
' noted that the user must know the order in which the
' 2x2 matrics are to be multipled, and that the user
' knows the form of the needed matrics.
' ********************************************
' Main Routine
' ********************************************
' This routine is responsible for calling the needed
' subprograms, and for geeting the number of elements
' in the system.
' ********************************************
DIM SYS(2,2), WORK(2,2), MATRIX2(2,2), ANS(2,2), INV(2,2)
GOSUB DIRECTIONS
DATAIN:
PRINT
INPUT "NUMBER OF 2x2 MATRICS TO BE USED.",N
IF N<2 THEN GOTO DATAIN
CLS
GOSUB REDUCE ' Multiply and reduce the system to one matric
GOSUB SOLVE ' Solve the resultant matrix
CLS
GOSUB RESULTS ' Print the results
PRINT "DO YOU WANT TO ANALAYSIS ANOTHER SYSTEM OF LENS";
INPUT ANSWER$
IF ANSWER$="YES" THEN GOTO DATAIN
STOP
DIRECTIONS:
PRINT " THIS PROGRAM IS DESIGNED TO SOLVE A SYSTEM OF LENS"
PRINT " USING 2x2 MATRIX MEATHODS. THE USER MUST KNOW THE"
PRINT " FORMAT OF THE 2x2 MATRIX FOR EACH LENS OR MIRROR"
RETURN
' ***************************************************
' This routine takes the inputted matricis and multiplies them
' together to get the final system matrix.
' ***************************************************
REDUCE:
PRINT "MATRIX 1"
CALL INMATRIX(WORK()) ' Enter the elements of the first matrix
PRINT "MATRIX 2"
CALL INMATRIX(MATRIX2()) ' Enter the elements of the second matrix
CALL MULTMATRIX(WORK(),MATRIX2(),SYS()) ' Multiply the first two matrics together
IF N=2 THEN RETURN
FOR COUNT=3 TO N
PRINT "MATRIX",COUNT
CALL INMATRIX(WORK()) ' Enter the remaining matrics
CALL MULTMATRIX(SYS(),WORK(),ANS()) ' Multiply remaining matrics
FOR II=1 TO 2
FOR JJ=1 TO 2
SYS(II,JJ)=ANS(II,JJ)
NEXT JJ
NEXT II
NEXT COUNT
RETURN
SOLVE:
INPUT "WHAT IS THE DISTANCE OF THE OBJECT TO THE FIRST LENS",R1
INPUT "WHAT IS THE FOCAL LENGTH OF THE FIRST LENS",F
R1P=1/((1/R1)-(1/F)) ' Comput image distance
CALL SOLVEMAT(R1,R1P,SYS(),R2,R2P,INV())
RETURN
RESULTS:
PRINT "THE IMAGE DISTANCE IS",R2P
F1=1/((1/R2)+(1/R2P))
PRINT "FOCAL LENGTH OF SYSTEM IS",F1
RETURN
SUB INMATRIX(A(2,2)) STATIC
FOR II=1 TO 2
FOR JJ=1 TO 2
PRINT "ELEMANT (";II;",";JJ;")";
INPUT A(II,JJ)
NEXT JJ
NEXT II
END SUB
SUB MULTMATRIX(A(2,2),B(2,2),C(2,2)) STATIC
FOR I=1 TO 2
FOR J=1 TO 2
C(I,J)=0
FOR K=1 TO 2
C(I,J)=C(I,J)+A(I,K)*B(K,J)
NEXT K
NEXT J
NEXT I
END SUB
' *******************************************
' This routine first calculates the determinant of the
' resulant matrix, and then finds its inverse, by using
' methods that are for 2x2 matrics only. These can be
' found in any linear algrebra book. Finally the matrix is
' solved.
'********************************************
SUB SOLVEMAT(R1,R1P,C(2,2),R2,R2P,INV(2,2)) STATIC
DET=C(1,1)*C(2,2)-C(1,2)*C(2,1)
INV(1,1)=C(2,2)/DET
INV(1,2)=-C(1,2)/DET
INV(2,1)=-C(2,1)/DET
INV(2,2)=C(1,1)/DET
R2=R1*INV(1,1)+R1P*INV(1,2)
R2P=R1*INV(2,1)+R1P*INV(2,2)
END SUB